package com.rabbitmq.demo.listener;

import com.rabbitmq.client.Channel;
import com.rabbitmq.demo.pojo.Order;
import com.rabbitmq.demo.service.OrderService;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class MyMessageListener {

    @Autowired
    OrderService orderService;

    @RabbitListener(queues = "queue.order.dlx")
    public void getMyMessage(Message message, Channel channel) throws IOException {

        System.out.println(Long.valueOf(new String(message.getBody())));
        Long id = Long.valueOf(new String(message.getBody()));
        Order order = orderService.getById(id);
        if(order.getState()==1){
            order.setState(3);
        }
        orderService.update(order);

    }

}
